package com.itheima.reggie.controller;

import com.itheima.reggie.common.ResultInfo;
import com.itheima.reggie.domain.Cart;
import com.itheima.reggie.service.CartService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

//购物器模块
@RestController
public class CartController {
    @Autowired
    private CartService cartService;

    //添加购物车
    @PostMapping("/cart/add")
    public ResultInfo add(@RequestBody Cart cartParam) {
        //调用service
        Cart add = cartService.add(cartParam);
        //返回结果
        return ResultInfo.success(add);
    }

    //查看购物车
    @GetMapping("/cart/list")
    public ResultInfo findList() {
        //调用service
        List<Cart> carts = cartService.findList();
        //返回结果
        return ResultInfo.success(carts);
    }

    //修改购物车
    @PostMapping ("/cart/sub")
    public ResultInfo update(@RequestBody Cart cart) {
        //调用service
     Cart update= cartService.update(cart);
        //返回结果
        return ResultInfo.success(update);
    }

    //清空购物车
    @DeleteMapping("/cart/clean")
    public ResultInfo clean() {
        //调用service
        cartService.clean();
        //返回结果
        return ResultInfo.success();
    }

    //
}
